package com.dianping.cat.consumer.heartbeat.model.transform;

import com.dianping.cat.consumer.heartbeat.model.IEntity;
import com.dianping.cat.consumer.heartbeat.model.IVisitor;
import com.dianping.cat.consumer.heartbeat.model.entity.Detail;
import com.dianping.cat.consumer.heartbeat.model.entity.Disk;
import com.dianping.cat.consumer.heartbeat.model.entity.Extension;
import com.dianping.cat.consumer.heartbeat.model.entity.HeartbeatReport;
import com.dianping.cat.consumer.heartbeat.model.entity.Machine;
import com.dianping.cat.consumer.heartbeat.model.entity.Period;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  16 */   private Stack<Object> m_objs = new Stack();

  private HeartbeatReport m_heartbeatReport;


  public DefaultMerger() {}

  public DefaultMerger(HeartbeatReport heartbeatReport) {
    this.m_heartbeatReport = heartbeatReport;
    this.m_objs.push(heartbeatReport);
  }


  public HeartbeatReport getHeartbeatReport() { return this.m_heartbeatReport; }



/*  33 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  37 */     this.m_objs.push(to);
/*  38 */     from.accept(this);
/*  39 */     this.m_objs.pop();
  }


/*  43 */   protected void mergeDetail(Detail to, Detail from) { to.mergeAttributes(from); }



/*  47 */   protected void mergeDisk(Disk to, Disk from) { to.mergeAttributes(from); }



/*  51 */   protected void mergeExtension(Extension to, Extension from) { to.mergeAttributes(from); }


  protected void mergeHeartbeatReport(HeartbeatReport to, HeartbeatReport from) {
/*  55 */     to.mergeAttributes(from);
/*  56 */     to.getDomainNames().addAll(from.getDomainNames());
/*  57 */     to.getIps().addAll(from.getIps());
  }


/*  61 */   protected void mergeMachine(Machine to, Machine from) { to.mergeAttributes(from); }



/*  65 */   protected void mergePeriod(Period to, Period from) { to.mergeAttributes(from); }



  public void visitDetail(Detail from) {
/*  70 */     Detail to = (Detail)this.m_objs.peek();

/*  72 */     mergeDetail(to, from);
/*  73 */     visitDetailChildren(to, from);
  }


  protected void visitDetailChildren(Detail to, Detail from) {}


  public void visitDisk(Disk from) {
/*  81 */     Disk to = (Disk)this.m_objs.peek();

/*  83 */     mergeDisk(to, from);
/*  84 */     visitDiskChildren(to, from);
  }


  protected void visitDiskChildren(Disk to, Disk from) {}


  public void visitExtension(Extension from) {
/*  92 */     Extension to = (Extension)this.m_objs.peek();

/*  94 */     mergeExtension(to, from);
/*  95 */     visitExtensionChildren(to, from);
  }

  protected void visitExtensionChildren(Extension to, Extension from) {
/*  99 */     for (Detail source : from.getDetails().values()) {
/* 100 */       Detail target = to.findDetail(source.getId());

/* 102 */       if (target == null) {
/* 103 */         target = new Detail(source.getId());
/* 104 */         to.addDetail(target);
      }

/* 107 */       this.m_objs.push(target);
/* 108 */       source.accept(this);
/* 109 */       this.m_objs.pop();
    }
  }


  public void visitHeartbeatReport(HeartbeatReport from) {
/* 115 */     HeartbeatReport to = (HeartbeatReport)this.m_objs.peek();

/* 117 */     mergeHeartbeatReport(to, from);
/* 118 */     visitHeartbeatReportChildren(to, from);
  }

  protected void visitHeartbeatReportChildren(HeartbeatReport to, HeartbeatReport from) {
/* 122 */     for (Machine source : from.getMachines().values()) {
/* 123 */       Machine target = to.findMachine(source.getIp());

/* 125 */       if (target == null) {
/* 126 */         target = new Machine(source.getIp());
/* 127 */         to.addMachine(target);
      }

/* 130 */       this.m_objs.push(target);
/* 131 */       source.accept(this);
/* 132 */       this.m_objs.pop();
    }
  }


  public void visitMachine(Machine from) {
/* 138 */     Machine to = (Machine)this.m_objs.peek();

/* 140 */     mergeMachine(to, from);
/* 141 */     visitMachineChildren(to, from);
  }

  protected void visitMachineChildren(Machine to, Machine from) {
/* 145 */     for (Period source : from.getPeriods()) {
/* 146 */       Period target = to.findPeriod(source.getMinute());

/* 148 */       if (target == null) {
/* 149 */         target = new Period(source.getMinute());
/* 150 */         to.addPeriod(target);
      }

/* 153 */       this.m_objs.push(target);
/* 154 */       source.accept(this);
/* 155 */       this.m_objs.pop();
    }
  }


  public void visitPeriod(Period from) {
/* 161 */     Period to = (Period)this.m_objs.peek();

/* 163 */     mergePeriod(to, from);
/* 164 */     visitPeriodChildren(to, from);
  }

  protected void visitPeriodChildren(Period to, Period from) {
/* 168 */     for (Disk source : from.getDisks()) {
/* 169 */       Disk target = to.findDisk(source.getPath());

/* 171 */       if (target == null) {
/* 172 */         target = new Disk(source.getPath());
/* 173 */         to.addDisk(target);
      }

/* 176 */       this.m_objs.push(target);
/* 177 */       source.accept(this);
/* 178 */       this.m_objs.pop();
    }

/* 181 */     for (Extension source : from.getExtensions().values()) {
/* 182 */       Extension target = to.findExtension(source.getId());

/* 184 */       if (target == null) {
/* 185 */         target = new Extension(source.getId());
/* 186 */         to.addExtension(target);
      }

/* 189 */       this.m_objs.push(target);
/* 190 */       source.accept(this);
/* 191 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/heartbeat/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */